package engine.newUi
{
	import com.greensock.TweenLite;
	import com.greensock.easing.Circ;
	
	import engine.ui.lite.BaseUI;
	
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.TimerEvent;
	import flash.filters.BitmapFilterQuality;
	import flash.filters.GlowFilter;
	import flash.geom.Point;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	import flash.utils.Timer;
	
	import newx.NxSprite;
	import newx.StageInfo;
	import newx.com.ResManager;
	import newx.com.config.StaticIni;
	import newx.com.control.text.NxLabel;
	import newx.com.control.text.NxText;
	
	public class NoticeUI extends BaseUI
	{
		private static var _self	:NoticeUI;
		private var _messageTxt	:NxLabel;
		private var _timer			:Timer;
		private var _textFormat	:TextFormat;
		private var _bg			:MovieClip;
		private var _lab			:NxLabel;
		/**
		 * @editor wangpg 
		 */
		private var _showing		:Boolean;
		/***最小宽度**/
		private var _lowWidth:int = 215;
		
		
		/**
		 * 当完成初始化工作之后调用
		 */
		public static function getInstance():NoticeUI
		{
			if(_self == null)
			{
				_self	=	new NoticeUI();
			}
			return _self
		}
		
		public function NoticeUI(popupUI:Boolean=false)
		{
			super(popupUI);
//			this.layout = "center";
//			this.initPosX = 0;
//			this.initPosY = 200;
			mouseChildren	=	mouseEnabled	=	false;
			_bg = ResManager.newResClass("npcTalk_0") as MovieClip;
			_bg .width = 215;
			_bg.height = 83;
			addChild(_bg);
			_lab = new NxLabel();
			_lab.htmlStr = StaticIni.getSwfLangStr("UIString_1000141");
			_lab.x = (_bg.width - _lab.width)*.5;
			_lab.y = 45;
			addChild(_lab);
			_timer	=	new Timer(2000,1);
			_timer.addEventListener(TimerEvent.TIMER_COMPLETE,onTimerFinish);
			_textFormat	=	new TextFormat();
			_textFormat.size			=	14;
			_textFormat.bold 			=	true;
			_textFormat.color			=	StaticIni.getIniVar("Css_txt_notice", "txtStr");
			_messageTxt	=	new NxLabel();
			_messageTxt.mouseEnabled	=	false;
			addChild(_messageTxt);
			//hide();
			
			mouseChildren	=	mouseEnabled	=	false;
			_showing = false;
		}
		
		private function onTimerFinish(e:TimerEvent):void
		{
			_timer.stop();
			hide();
			
			_showing = false;
		}
		
		override public function afterHide():void
		{
			TweenLite.to(this, 1, {alpha:0, ease:Circ.easeOut,onComplete:tweenLiteComplete});
		}
		
		
		private function tweenLiteComplete():void
		{
			if(parent!=null)
			{
				_messageTxt.htmlText	=	""
//				parent.removeChild(this);
				this.hide();
			}
		}
		
		/**
		 *更新界面位置 
		 * 
		 */
		public function updataView():void
		{
			var w:int;
			var h:int;
			if( this.windowBG != null )
			{
				w = this.windowBG.width;
				h = this.windowBG.height;
			}else
			{
				w = this.width;
				h = this.height;
			}
			if(parent)
			{
				var point : Point = parent.globalToLocal( new Point( ( StageInfo.stage.stageWidth - w ) * .5,
					( StageInfo.stage.stageHeight - h ) * .5 ) );
				x = point.x;
				y = 0;
			}
		}
		
		public function showInfo(value:String):void
		{
			if(!value)return ;//是空还显示个毛线；
			this.alpha = 1;

			_timer.reset();

			_messageTxt.htmlText	=	value;//StaticIni.getSwfLangStr("UIString_1000140")
			_messageTxt.setTextFormat(_textFormat);
			
			_showing = true;
			_bg.width = _messageTxt.width+20;
			if(_bg.width < _lowWidth)
			{
				_bg.width = _lowWidth;
			}
			_messageTxt.x = (_bg.width - _messageTxt.width)*.5;;
			_lab.x = (_bg.width - _lab.width)*.5;
			_messageTxt.y = 20;
//			StageInfo.uiSpace.addChild(this);
			this.alpha = 1;
			this.show(StageInfo.systemSpace);
			updataView();
			_timer.start();
		}
	}
}